<template>
  <!--采购发票(付款发票)-->
  <div>
    <div>
      <!--value报错-->
      <span style="padding: 0 10px"><i class="font-14 el-icon-s-open"></i></span>
      <el-select v-model="filterValue" value-key="value" @change="initData(currPage,pageSize,filterValue,content)" placeholder="全部数据" style="width: 120px">
        <el-option v-for="item in filterOptions" :key="item.value" :label="item.label" :value="item">
        </el-option>
      </el-select>
      <span style="padding: 0 10px 0 30px"><i class="fn el-icon-message-solid"></i></span>
      <el-input v-model="content" placeholder="请输入内容" style="width: 150px"></el-input>
      <el-select v-model="vagueValue" placeholder="收票日期" style="width: 140px">
        <el-option v-for="item in vagueOptions" :key="item.value"
                   :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <el-button @click="initData(currPage,pageSize,filterValue,content)" icon="el-icon-search" size="small" circle></el-button>
    </div>
    <!--新建-->
    <el-row style="margin-top: 15px;overflow: hidden;">
      <el-col :span="12" class="col-sm-6 text-left" style="margin-bottom: 20px">
        <span>采购发票</span>
        <small class="text-muted font-13">共{{totalSize}}条</small>
      </el-col>
      <el-col :span="12" class="col-sm-6 text-right">
        <el-button type="text" @click="dialogFormVisible = true">
          <el-button size="small" icon="el-icon-circle-plus-outline">新建</el-button>
        </el-button>
      </el-col >
      <!--采购发票dialog-->
      <el-dialog title="采购发票" :visible.sync="dialogFormVisible" width="60%" style="color: #333333"
                 @open="openDialog" @close="closeDialog" >
        <el-form :model="paymentInvoice" ref="payInvoice" label-width="100px" :rules="rules">
          <hr style="margin-bottom: 15px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="摘要:" prop="paymentInvoiceAbstract">
                <el-input v-model="paymentInvoice.paymentInvoiceAbstract "style="width:79%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="票据类型:" prop="paymentInvoicePaperType">
                <el-select v-model="paymentInvoice.paymentInvoicePaperType" placeholder="未选"  style="width: 79%">
                  <el-option v-for="item in flOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="金额:" prop="paymentInvoiceAmount">
                <el-input v-model.number="paymentInvoice.paymentInvoiceAmount" style="width: 79%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="收票日期:" prop="paymentInvoiceTicketDate">
                <el-date-picker v-model="paymentInvoice.paymentInvoiceTicketDate" type="date" placeholder="选择日期" style="width: 79%"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="采购单:" prop="purchaseByPurchaseId">
                <el-select v-model="paymentInvoice.purchaseByPurchaseId" value-key="purchaseId" placeholder="未选" style="width: 91%">
                  <el-option v-for="item in purchaseList" :key="item.purchaseId" :label="item.purchaseTheme" :value="item">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="经手人:" prop="employeeByEmpId.empName">
                <el-input :disabled="true" v-model="paymentInvoice.employeeByEmpId.empName" style="width: 79%">
                  <el-button @click="openEmpDialog" slot="append" icon="el-icon-search"></el-button>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="期次:">
                <el-select v-model="paymentInvoice.paymentInvoicePeriods" placeholder="未选"  style="width: 79%">
                  <el-option v-for="item in qcOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="供应商/客户:" prop="customerByCustomerId.customerName">
                <el-input :disabled="true" v-model="paymentInvoice.customerByCustomerId.customerName" style="width: 91%"></el-input>
              </el-form-item>
              <div class="form-inline" v-show="isCustomer">
                <el-input v-model="customerValue" clearable size="medium" placeholder="拼音.字母.关键字" style="width: 20%"></el-input>
                <el-button @click="findCustomer" size="medium" icon="el-icon-search"></el-button>
                <el-popover placement="top" v-model="visible">
                  <div style="margin-bottom: 10px">
                    <span>查询条件:{{customerValue}}</span>
                    <span @click="cleanCustomer" class="cursor" style="float: right"><i class="el-icon-error"></i></span>
                  </div>
                  <ul class="cu-ul" v-if="customerList2 !== ''">
                    <li @click="choiceCustomer2(item)" v-for="item in customerList2">{{item.customerName}}</li>
                  </ul>
                  <div style="margin: 5px 0;text-align: center" v-if="customerList2 == ''">
                    <i class="el-icon-warning-outline"/>没有符合条件的客户！
                  </div>
                </el-popover>
                <el-tooltip class="item" effect="dark" content="浏览选择客户" placement="bottom">
                  <el-button @click="innerVisible(cusCurrPage,cusPageSize)" size="medium" icon="el-icon-s-operation"></el-button>
                </el-tooltip>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="是否付款:">
                <el-select placeholder="未选" v-model="paymentInvoice.paymentInvoiceWhetherPay" style="width: 79%" >
                  <el-option v-for="item in payOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否付款计划:" >
                <el-select placeholder="未选"  style="width: 79%" v-model="paymentInvoice.paymentInvoiceWhetherPayPlan">
                  <el-option v-for="item in payPlanOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="发票号码:">
                <el-input :disabled="true" v-model="paymentInvoice.paymentInvoiceNo" placeholder="自动生成" style="width: 91%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="备注:">
                <el-input v-model="paymentInvoice.paymentInvoiceNote" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容"  style="width: 91%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12" :offset="6">
              <el-form-item>
                <el-button @click="addPayInvoice" type="primary">保存</el-button>
                <el-button @click="dialogFormVisible = false">取消</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <!--内层dialog-->
        <el-dialog width="30%" title="客户选择" :visible.sync="innerDialog" append-to-body>
          <!--选择客户-->
          <el-table :data="customerList" style="width: 100%">
            <el-table-column prop="customerId" label="客户编号" >
            </el-table-column>
            <el-table-column prop="customerName" label="客户名" >
            </el-table-column>
            <el-table-column label="请选择" >
              <template slot-scope="scope">
                <el-button size="mini" @click="choiceCustomer(scope.row)" icon="el-icon-check" type="primary" circle style="margin-left: 10px"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-row style="margin-top:10px">
            <el-col :span="16">
              <el-pagination layout="prev, pager, next, jumper" :total="cusTotalSize" @current-change="cusChangePage"
                             :current-page.sync="cusCurrPage" :page-size="cusPageSize"></el-pagination>
            </el-col>
          </el-row>
        </el-dialog>
        <!--内层dialog员工-->
        <el-dialog width="30%" title="人员选择" :visible.sync="innerDialogEmp" append-to-body
                   @close="closeInnerDialogEmp">
          <div>
            <el-collapse v-model="activeName">
              <el-collapse-item v-for ="(dept,index) in deptList" :title="dept.deptName" :key="index" :name="dept.deptId">
                <ul class="emp-ul">
                  <li @click="choiceEmp(emp)" v-for="(emp,index) in dept.employeeByDeptId">
                    <span v-if="index !== dept.employeeByDeptId.length-1" class="line-style"></span>
                    <span v-if="index === dept.employeeByDeptId.length-1" class="line-style-end"></span>
                    <span class="">{{emp.empName}}</span>
                  </li>
                </ul>
              </el-collapse-item>
            </el-collapse>
          </div>
        </el-dialog>
      </el-dialog>
    </el-row>
    <!--采购发票表格-->
    <el-table ref="multipleTable" :data="paymentInvoiceList" tooltip-effect="dark" id="outTable"
              style="width: 100%" :header-cell-style="rowClass"  @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" ></el-table-column>
      <el-table-column prop="paymentInvoiceId" label="ID" sortable width="60"></el-table-column>
      <el-table-column label="摘要" >
        <template slot-scope="scope">
          <div @click="handleEdit(scope.row)" class="cursor">
            <i class="el-icon-caret-right" ></i>
            <span>{{scope.row.paymentInvoiceAbstract}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="票据类型" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.paymentInvoicePaperType === 1">{{flOptions[0].label}}</span>
          <span v-if="scope.row.paymentInvoicePaperType === 2">{{flOptions[1].label}}</span>
          <span v-if="scope.row.paymentInvoicePaperType === 3">{{flOptions[2].label}}</span>
          <span v-if="scope.row.paymentInvoicePaperType === 4">{{flOptions[3].label}}</span>
        </template>
      </el-table-column>
      <el-table-column label="金额" width="100" sortable>
        <template slot-scope="scope">
          <span>￥{{scope.row.paymentInvoiceAmount}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="paymentInvoiceNo" label="发票号码" ></el-table-column>
      <el-table-column prop="paymentInvoiceTicketDate" label="收票日期" sortable width="110">
        <template slot-scope="scope">
          <span>{{scope.row.paymentInvoiceTicketDate | formatDateJudge}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="employeeByEmpId.empName" label="经手人" ></el-table-column>
      <el-table-column label="是否付款" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.paymentInvoiceWhetherPay === 1">{{payOptions[0].label}}</span>
          <span v-if="scope.row.paymentInvoiceWhetherPay === 2">{{payOptions[1].label}}</span>
        </template>
      </el-table-column>
      <el-table-column label="采购单" >
        <template slot-scope="scope">
          <span>{{scope.row.purchaseByPurchaseId.purchaseTheme}}</span>
          <router-link :to="{path:'/purchaseview',query: {purId: scope.row.purchaseByPurchaseId.purchaseId}}">
            <span style="color: #333333"><i class="el-icon-s-cooperation"></i></span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column prop="client" label="供应商(客户)" >
        <template slot-scope="scope">
          <div style="color: #333333">
            <span>{{scope.row.customerByCustomerId.customerName}}</span>
            <el-tooltip class="item" effect="dark" content="打开详细页面" placement="bottom">
              <router-link :to="{path:'/customerview',query: {customerId: scope.row.customerByCustomerId.customerId}}">
                <span style="color: #333333">
                  <i class="el-icon-s-cooperation"></i>
                </span>
              </router-link>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="" label="操作" width="120px">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)"
                     icon="el-icon-edit" type="primary" circle style="margin-left: 10px"></el-button>
          <el-button size="mini" @click="handleDelete(scope.row)"
                     icon="el-icon-delete" type="danger" circle></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-row style="margin-top:10px">
      <el-col :span="8">
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button style="padding: 12px 12px" icon="el-icon-delete" @click="handleDeleteMany" type="danger"></el-button>
        </el-tooltip>
      </el-col>
      <el-col :span="13">
        <el-pagination layout="sizes,prev,pager, next, jumper" :total="totalSize" @current-change="changePage"
                       :current-page.sync="currPage" :page-size="pageSize" :page-sizes="pageSizes" @size-change="changeSize"></el-pagination>
      </el-col>
      <el-col :span="3">
        <el-tooltip class="item" effect="dark" content="打印列表" placement="bottom">
          <el-button @click="handleWindowPrint('#outTable', '列表打印')" style="padding: 12px 12px" type="info" plain  icon="el-icon-printer"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="批量导出Excel格式数据" placement="bottom">
          <el-button @click="batchExportExcel" style="padding: 12px 12px" type="info" plain  icon="el-icon-document-copy"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="导出Excel格式数据" placement="bottom">
          <el-button @click="exportExcel" style="padding: 12px 12px" type="info" plain  icon="el-icon-document-remove"></el-button>
        </el-tooltip>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import XLSX from "xlsx";
  import FileSaver from "file-saver";

  export default {
  data () {
    return {
      emp: {},
      dialogFormVisible: false,
      paymentInvoiceList: [],
      purchaseList: [], // 采购集合分页
      customerList: [], // 员工客户集合
      paymentInvoice:{
        paymentInvoiceId:0,
        paymentInvoiceAbstract:'',
        paymentInvoicePaperType:'',
        paymentInvoiceTicketDate:'',
        paymentInvoiceAmount:'',
        paymentInvoicePeriods:'',
        paymentInvoiceWhetherPay:'',
        paymentInvoiceWhetherPayPlan:'',
        paymentInvoiceNo:'',
        paymentInvoiceNote:'',
        customerByCustomerId:{},
        purchaseByPurchaseId:'',
        employeeByEmpId:{}
      },
      pageSize: 10, // 分页页大小
      pageSizes:[10,20,30],//页大小数组
      currPage: 1, // 当前页码，默认为1
      totalSize: 0, // 总记录数
      cusPageSize: 5, // 分页页大小
      cusCurrPage: 1, // 当前页码，默认为1
      cusTotalSize: 0, // 总记录数
      content: '',// input内容
      isCustomer: true, // 客户搜索显示
      innerDialog: false,// 内层dialog客户
      innerDialogEmp: false,// 内层dialog员工
      activeName: [],
      deptList:[],
      content: '',// input内容
      customerValue:'',// 模糊查询客户
      customerList2:[],// 模糊查询结果
      visible: false,// 模糊搜索结果
      mulSelection: [],
      rules: {
        paymentInvoiceAbstract: [
          { required: true, message: '必须填', trigger: 'blur'},
        ],
        paymentInvoicePaperType: [
          { required: true, message: '必须填', trigger: 'blur'},
        ],
        paymentInvoiceAmount: [
          { required: true, message: '必须填'},
          { type: 'number', message: '必须为数字'}
        ],
        paymentInvoiceTicketDate: [
          { required: true, message: '必须填', trigger: 'blur' }
        ],
        'customerByCustomerId.customerName': [
          { required: true, message: '请选择客户', trigger: 'blur' }
        ],
        'employeeByEmpId.empName': [
          { required: true, message: '请选择负责人', trigger: 'blur' }
        ],
        purchaseByPurchaseId: [
          { required: true, message: '必须填', trigger: 'blur' }
        ],
      },
      qcOptions: [{
        value: 1,
        label: '1'
      }, {
        value: 2,
        label: '2'
      }, {
        value: 3,
        label: '3'
      }, {
        value: 4,
        label: '4'
      }, {
        value: 5,
        label: '5'
      }, {
        value: 6,
        label: '6'
      },{
        value: 7,
        label: '7'
      }, {
        value: 8,
        label: '8'
      }, {
        value: 9,
        label: '9'
      }, {
        value: 10,
        label: '10'
      }, {
        value: 11,
        label: '11'
      }, {
        value: 12,
        label: '12'
      }],
      flOptions: [{
        value: 1,
        label: '增值'
      }, {
        value: 2,
        label: '普通国税'
      }, {
        value: 3,
        label: '普通地税'
      },{
        value: 4,
        label: '收据'
      }],
      payOptions: [{
        value: 1,
        label: '未付'
      }, {
        value: 2,
        label: '已付'
      }],
      payPlanOptions: [{
        value: 1,
        label: '未建'
      }, {
        value: 2,
        label: '已建'
      }, {
        value: 3,
        label: '已付款无须计划'
      }],
      filterOptions: [{
        value: 0,
        num:0,
        label: '全部数据'
      }, {
        value: 1,
        num:1,
        label: '增值'
      }, {
        value: 2,
        num:2,
        label: '普通国税'
      }, {
        value: 3,
        num:3,
        label: '普通地税'
      }, {
        value: 4,
        num:4,
        label: '收据'
      }, {
        value: 5,
        num:1,
        label: '未付'
      }, {
        value: 6,
        num:2,
        label: '已付'
      }],
      filterValue:{value:0,num:0},
      vagueOptions: [{
        value: 1,
        label: '收票日期'
      }],
      vagueValue: 1,
      selectList:[]
    }
  },
  methods: {
    // 查询当前员工
    loginEmp() {
      this.$axios.get('http://localhost:8088/emp')
        .then(v => {
          this.emp = v.data
        })
        .catch(function (v) {
        })
    },
    // 分页查询所有
    initData(currPage, pageSize,vague,content) {
      this.content = ''
      this.$axios.get('http://localhost:8088/pay-invoice-list', {
        params: {
          page: currPage,
          size: pageSize,
          value: vague.value,
          num:  vague.num,
          payDate: content
        }
      })
        .then(v => {
          this.paymentInvoiceList = v.data.rows
          this.totalSize = v.data.total
        })
        .catch(function (v) {
        })
    },
    // 付款记录表格分页
    changePage(val) {
      this.initData(val, this.pageSize,this.vagueValue,this.content)
    },
    //改变页大小
    changeSize(val){
      this.pageSize = val
      this.currPage = 1
      this.initData(this.currPage,this.pageSize,this.filterValue,this.content)
    },
    // 查询所有采购
    findPurchaseList(cusId) {
      this.$axios.get('http://localhost:8088/pur-cus-list',{
        params:{
          cusId:cusId
        }
      })
        .then(v => {
          this.purchaseList = v.data
        })
        .catch(function (v) {
        })
    },
    // 修改数据回显
    handleEdit(val) {
      this.dialogFormVisible = true
      this.paymentInvoice.paymentInvoiceId = val.paymentInvoiceId
      this.paymentInvoice.paymentInvoiceAbstract = val.paymentInvoiceAbstract
      this.paymentInvoice.paymentInvoicePaperType = val.paymentInvoicePaperType
      this.paymentInvoice.paymentInvoiceTicketDate = val.paymentInvoiceTicketDate
      this.paymentInvoice.paymentInvoiceAmount = val.paymentInvoiceAmount
      this.paymentInvoice.paymentInvoicePeriods = val.paymentInvoicePeriods
      this.paymentInvoice.paymentInvoiceWhetherPay = val.paymentInvoiceWhetherPay
      this.paymentInvoice.paymentInvoiceWhetherPayPlan = val.paymentInvoiceWhetherPayPlan
      this.paymentInvoice.paymentInvoiceNo = val.paymentInvoiceNo
      this.paymentInvoice.paymentInvoiceNote = val.paymentInvoiceNote
      this.paymentInvoice.customerByCustomerId = val.customerByCustomerId
      this.paymentInvoice.employeeByEmpId = val.employeeByEmpId
      this.paymentInvoice.purchaseByPurchaseId = val.purchaseByPurchaseId
      this.findPurchaseList(val.customerByCustomerId.customerId)
      this.isCustomer = false
    },
    // 新增、修改
    addPayInvoice() {
      if (this.paymentInvoice.paymentInvoiceId === 0){
        this.paymentInvoice.paymentInvoiceNo = this.payNo()
      }
      this.$refs.payInvoice.validate((valid) => {
        if (valid) {
          this.$axios.post('http://localhost:8088/save-pay-invoice',this.paymentInvoice)
            .then(v => {
              this.initData(this.currPage,this.pageSize,this.filterValue,this.content)
              this.dialogFormVisible= false
              this.$message({
                message: '已保存',
                type: 'success'
              });
            })
            .catch(function (v) {
            })
        } else {
          console.log('error submit!!');
          return false;
        }
      })

    },
    // 打开dialog事件
    openDialog() {
      if (this.paymentInvoice.paymentInvoiceId === 0){
        this.paymentInvoice.employeeByEmpId = this.emp
        this.paymentInvoice.paymentInvoiceWhetherPay = 1
        this.paymentInvoice.paymentInvoiceWhetherPayPlan = 1
        this.paymentInvoice.paymentInvoiceTicketDate = this.addDate()
      }
    },
    // 关闭dialog事件
    closeDialog() {
      this.$refs.payInvoice.resetFields()
      this.paymentInvoice = {
        paymentInvoiceId:0,
        paymentInvoiceAbstract:'',
        paymentInvoicePaperType:'',
        paymentInvoiceTicketDate:'',
        paymentInvoiceAmount:'',
        paymentInvoicePeriods:'',
        paymentInvoiceWhetherPay:'',
        paymentInvoiceWhetherPayPlan:'',
        paymentInvoiceNo:'',
        paymentInvoiceNote:'',
        customerByCustomerId:{},
        purchaseByPurchaseId:'',
        employeeByEmpId:{}
      }
      this.purchaseList = []
      this.isCustomer = true
    },
    // 打开内层dialog查询供应商
    innerVisible(cusCurrPage, cusPageSize) {
      this.$axios.get('http://localhost:8088/emp-customer-list', {
        params: {
          page: cusCurrPage,
          size: cusPageSize,
        }
      })
        .then(v => {
          this.customerList = v.data.rows
          this.cusTotalSize = v.data.total
        })
        .catch(function (v) {
        })
      this.innerDialog = true
    },
    // 查询客户分页
    cusChangePage(val) {
      // val就是当前页码
      this.innerVisible(val, this.cusPageSize)
    },
    // 选择客户
    choiceCustomer(val) {
      this.paymentInvoice.customerByCustomerId = val
      this.paymentInvoice.purchaseByPurchaseId = ''
      this.findPurchaseList(val.customerId)
      this.innerDialog = false;
    },
    // 模糊查询客户
    findCustomer() {
      if (this.customerValue != '') {
        this.visible = true
        this.$axios.get('http://localhost:8088/emp-fuzzy-customer-list', {
          params: {
            customerName: this.customerValue
          }
        })
          .then(v => {
            this.customerList2 = v.data
          })
          .catch(function (v) {
          })
      } else {
        this.visible = false
      }
    },
    // 模糊选择客户
    choiceCustomer2(val) {
      this.paymentInvoice.customerByCustomerId = val
      this.paymentInvoice.purchaseByPurchaseId = ''
      this.findPurchaseList(val.customerId)
      this.customerValue = ''
      this.visible = false
    },
    // 失去焦点关闭模糊搜索框
    cleanCustomer() {
      this.visible = false
      this.customerValue = ''
    },
    //查询部门员工
    findDeptList () {
      this.$axios.get('http://localhost:8088/dept-emp-list')
        .then(v => {
          this.deptList = v.data
          for(let i = 1;i <= this.deptList.length;i++){
            this.activeName.push(i)
          }
        })
        .catch(function (v) {})
    },
    //打开员工dialog
    openEmpDialog(){
      this.innerDialogEmp = true
      this.findDeptList()
    },
    // 选择员工
    choiceEmp(val) {
      this.paymentInvoice.employeeByEmpId = val
      this.innerDialogEmp = false;
    },
    //关闭员工diglog事件
    closeInnerDialogEmp(){
      this.activeName = []
    },
    // 删除提示
    handleDelete(val) {
      this.$confirm('此操作将永久删除该采购发票, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deletePay(val.paymentInvoiceId)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 批量删除提示
    handleDeleteMany() {
      this.$confirm('此操作将永久删除勾选采购发票, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteAll()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 获取批量删除对象集合
    handleSelectionChange(val) {
      this.mulSelection = val
    },
    // 删除axios
    deletePay(payId) {
      this.$axios.post('http://localhost:8088/delete-pay-invoice',
        this.qs.stringify({payId: payId}))
        .then(v => {
          this.initData(this.currPage,this.pageSize,this.filterValue,this.content)
        })
        .catch(function (v) {
        })
    },
    // 删除所有
    deleteAll() {
      this.mulSelection.forEach(row => {
        this.deletePay(row.paymentInvoiceId)
      })
    },
    // 发票单号
    payNo() {
      var payNo = "";
      for (var i = 0; i < 4; i++) //j位随机数，用以加在时间戳后面。
      {
        payNo += Math.floor(Math.random() * 10);
      }
      payNo = 'CGFP' + this.addDateNum() + payNo;
      return payNo;
    },
    // 获取当前日期20200206
    addDateNum () {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      var currentdate = year  + month  + strDate;
      return currentdate;
    },
    // 获取当前日期
    addDate () {
      var date = new Date();
      var seperator1 = "-";
      var seperator2 = ":";
      var month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
      var strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
      var currentdate = date.getFullYear() + seperator1  + month  + seperator1  + strDate
      return currentdate
    },
    // pdf打印
    handleWindowPrint (ele, fileName) {
      document.body.innerHTML = document.querySelector(ele).outerHTML
      // 转异步 等待dom元素渲染（样式）完毕在打印
      setTimeout(() => {
        // 打印
        window.print()
        // 刷新页面
        window.location.reload()
      }, 20)
    },
    //导出excel
    exportExcel () {
      var xlsxParam = { raw: true };//转换成excel时，使用原始的格式
      var wb = XLSX.utils.table_to_book(document.querySelector("#outTable"),xlsxParam);
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: "application/octet-stream;charset=utf-8" }),
          "付款发票导出.xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    //批量导出excel batchList
    batchExportExcel(){
      this.mulSelection.forEach((item,i)=>{
        this.$set(item,'paymentInvoiceId',item.paymentInvoiceId);
        this.$set(item,'paymentInvoiceAbstract',item.paymentInvoiceAbstract)
        if(item.paymentInvoicePaperType !== null){
          this.$set(item,'paymentInvoicePaperType',this.flOptions[item.paymentInvoicePaperType - 1].label);
        }
        this.$set(item,'paymentInvoiceAmount','￥'+item.paymentInvoiceAmount);
        this.$set(item,'paymentInvoiceNo',item.paymentInvoiceNo);
        this.$set(item,'paymentInvoiceTicketDate',item.paymentInvoiceTicketDate);
        this.$set(item,'empName',item.employeeByEmpId.empName)
        if(item.paymentInvoiceWhetherPay !== null){
          this.$set(item,'paymentInvoiceWhetherPay',this.payOptions[item.paymentInvoiceWhetherPay - 1].label);
        }
        this.$set(item,'purchaseTheme',item.purchaseByPurchaseId.purchaseTheme);
        this.$set(item,'customerName',item.customerByCustomerId.customerName);
        this.selectList.splice(i,0,item);
      })
      //excel数据导出
      require.ensure([], () => {
        const {
          export_json_to_excel
        } = require('../js/Export2Excel');
        const tHeader = ['ID','摘要','票据类型','金额','发票号码','收票日期','经手人','是否付款','采购单','供应商(客户)'];
        const filterVal = ['paymentInvoiceId','paymentInvoiceAbstract','paymentInvoicePaperType','paymentInvoiceAmount','paymentInvoiceNo','paymentInvoiceTicketDate',
          'empName','paymentInvoiceWhetherPay','purchaseTheme','customerName'];
        const list = this.selectList;
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '付款发票批量导出');
      })
      this.initData(this.currPage,this.pageSize,this.filterValue,this.content)
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    // 表头靠左样式
    rowClass(){
      return "text-align:left"
    }
  },
  created() {
    this.loginEmp()
    this.initData(this.currPage,this.pageSize,this.filterValue,this.content)
  },
  filters: {
    formatDateJudge: function(time) {
      if(time != null && time != "")
      {
        let date = new Date(time);
        let currentDate = new Date()
        let seperator1 = "-";
        let month = currentDate.getMonth() + 1<10? "0"+(currentDate.getMonth() + 1):currentDate.getMonth() + 1;
        let strDate = currentDate.getDate()<10? "0" + currentDate.getDate():currentDate.getDate();
        let today = currentDate.getFullYear() + seperator1  + month  + seperator1  + strDate
        let todayTime = new Date(today)
        let yesterday = todayTime.setDate(todayTime.getDate() - 1)
        let beforeYesterday = todayTime.setDate(todayTime.getDate() - 1)
        let tomorrow = todayTime.setDate(todayTime.getDate() + 3)
        let afterTomorrow = todayTime.setDate(todayTime.getDate() + 1)
        todayTime.setDate(todayTime.getDate() - 2)
        if (date.getTime() === todayTime.getTime()){
          return '今天'
        }else if (date.getTime() ===  yesterday){
          return '昨天'
        }else if (date.getTime() ===  beforeYesterday){
          return '前天'
        }else if (date.getTime() ===  tomorrow){
          return '明天'
        }else if (date.getTime() ===  afterTomorrow){
          return '后天'
        }else {
          return time
        }
      }else{
        return "";
      }
    }
  }
}
</script>

<style>
</style>
